/*
 * @Author: HuangBingQuan <17671241237@163.com>
 * @Date: 2024-03-09 00:09:25
 * @LastEditTime: 2024-03-09 00:55:17
 * @FilePath: /san-zi-qi/src/components/BoardComp/BoardComp.tsx
 */
import React from 'react'
import { ChessType } from '../../type/enums'
import { ChessComp } from '../ChessComp/ChessComp'
import "./BoardComp.scss";

interface IProps {
    chesses: ChessType[],
    isGameOver?: boolean,
    onClick?: (index: number)=> void
}

export const BoardComp: React.FC<IProps> = (props)=> {
    const isGameOver = props.isGameOver as boolean;
    const list = props.chesses.map((type, index) => 
        <ChessComp key={index} type={type} onClick={()=> {
            if(props.onClick && !isGameOver) {
                props.onClick(index);
            }
        }}/>
    );
    return (
        <div className='board'>
            { list }
        </div>
    )
}

BoardComp.defaultProps = {
    isGameOver: false
}